/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package fy.form.groovy;

import com.seeyon.apps.collaboration.manager.ColManager;
import com.seeyon.apps.collaboration.po.ColSummary;
import com.seeyon.ctp.common.AppContext;
import com.seeyon.ctp.common.content.mainbody.CtpContentAllBean;
import com.seeyon.ctp.common.content.mainbody.MainbodyManager;
import com.seeyon.ctp.util.ParamUtil;
import com.seeyon.ctp.util.json.JSONUtil;
import com.seeyon.v3x.services.AuthorityService;
import com.seeyon.v3x.services.V3XLocator;
import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 *
 * @author Administrator
 */
public class FormReaderFunc16 {

    private static final Log logger = LogFactory.getLog(FormReaderFunc16.class);

    public static String getFlow(Object object) {
        try {
            String json_params = "{\n"
                    + "    \"_currentDiv\": {\n"
                    + "        \"_currentDiv\": \"0\"\n"
                    + "    },\n"
                    + "    \"mainbodyDataDiv_0\": {\n"
                    + "        \"id\": \"3611211200780913843\",\n"
                    + "        \"createId\": \"-1825607432309486470\",\n"
                    + "        \"createDate\": \"2015-12-20 19:58:51\",\n"
                    + "        \"modifyId\": \"\",\n"
                    + "        \"modifyDate\": \"\",\n"
                    + "        \"moduleType\": \"1\",\n"
                    + "        \"moduleId\": \"6953426441754991455\",\n"
                    + "        \"contentType\": \"20\",\n"
                    + "        \"moduleTemplateId\": \"2004410850892464500\",\n"
                    + "        \"contentTemplateId\": \"2757282056075166511\",\n"
                    + "        \"sort\": \"0\",\n"
                    + "        \"title\": \"(自动发起)返厂记录1212(郑志诚 2015-12-20 19:58)\",\n"
                    + "        \"content\": \"6953426441754991455\",\n"
                    + "        \"rightId\": \"-8935282417671385488\",\n"
                    + "        \"status\": \"STATUS_RESPONSE_VIEW\",\n"
                    + "        \"viewState\": \"1\",\n"
                    + "        \"contentDataId\": \"6953426441754991455\"\n"
                    + "    },\n"
                    + "    \"formmain_4108\": [],\n"
                    + "    \"attachmentInputs\": []\n"
                    + "}";

            ColManager cm = V3XLocator.getInstance().lookup(ColManager.class);//checkAffairValid
            cm.checkAffairValid("-2262416499172031795");
//            MHttpServletRequest request = MAppContextUtils.getHttpServletRequest();
//            request.setParameter("notSaveDB", "true");
//            AppContext.putThreadContext("THREAD_CONTEXT_REQUEST_KEY", request);

            AppContext.putThreadContext("THREAD_CONTEXT_JSONOBJ_KEY", JSONUtil.parseJSONString(json_params, null));

            Map div = ParamUtil.getJsonDomain("_currentDiv");
            String curDiv = (String) div.get("_currentDiv");
            CtpContentAllBean contentAll = (CtpContentAllBean) ParamUtil.mapToBean(ParamUtil.getJsonDomain((new StringBuilder("mainbodyDataDiv_")).append(curDiv).toString()), CtpContentAllBean.class, true);

//            CtpContentAllBean contentAll = (CtpContentAllBean) ParamUtil.mapToBean((Map) json.get("mainbodyDataDiv_0"), CtpContentAllBean.class, true);
            MainbodyManager ctpMainbodyManager = V3XLocator.getInstance().lookup(MainbodyManager.class);

            ctpMainbodyManager.transContentSaveOrUpdate(contentAll);

            logger.info("自动完成 success");

        } catch (Exception ex) {
            ex.printStackTrace();
            logger.error(ex);
        }
        return "测试";
    }

    public static String getFlow1(Object object) {
//        ColSummary s;
        String result = "";
        AuthorityService as;
        try {
//            FormTriggerManager frm = V3XLocator.getInstance().lookup(FormTriggerManager.class);
//            frm.doTrigger(null, i, l, FormTriggerBean.TriggerConditionState.FlowSend)

//            as = V3XLocator.getInstance().lookup(AuthorityService.class);
//
//            UserToken token = as.authenticate("service-admin", "123456");
//
//            FlowService fs = V3XLocator.getInstance().lookup(FlowService.class);
////            result = ds.exportFlow2(token.toString(), 6941744530972217114L);
//            String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?> \n"
//                    + "<formExport version=\"2.0\">\n"
//                    + "    <summary id=\"-1\" name=\"formmain_3981\"/>\n"
//                    + "    <values>\n"
//                    + "        <column name=\"人员选择器\">\n"
//                    + "            <value/>\n"
//                    + "        </column>\n"
//                    + "        <column name=\"部门选择器\">\n"
//                    + "            <value/>\n"
//                    + "        </column>\n"
//                    + "        <column name=\"单位选择器\">\n"
//                    + "            <value/>\n"
//                    + "        </column>\n"
//                    + "        <column name=\"子公司\">\n"
//                    + "            <value/>\n"
//                    + "        </column>\n"
//                    + "        <column name=\"日期\">\n"
//                    + "            <value/>\n"
//                    + "        </column>\n"
//                    + "        <column name=\"单据编号\">\n"
//                    + "            <value><![CDATA[20151200040]]></value>\n"
//                    + "        </column>\n"
//                    + "        <column name=\"出门业务种类\">\n"
//                    + "            <value/>\n"
//                    + "        </column>\n"
//                    + "        <column name=\"出门业务种类其他\">\n"
//                    + "            <value/>\n"
//                    + "        </column>\n"
//                    + "        <column name=\"联系电话\">\n"
//                    + "            <value/>\n"
//                    + "        </column>\n"
//                    + "        <column name=\"出厂门\">\n"
//                    + "            <value/>\n"
//                    + "        </column>\n"
//                    + "        <column name=\"车号\">\n"
//                    + "            <value/>\n"
//                    + "        </column>\n"
//                    + "        <column name=\"出厂原因\">\n"
//                    + "            <value/>\n"
//                    + "        </column>\n"
//                    + "        <column name=\"特证单位\">\n"
//                    + "            <value/>\n"
//                    + "        </column>\n"
//                    + "        <column name=\"票证号\">\n"
//                    + "            <value/>\n"
//                    + "        </column>\n"
//                    + "        <column name=\"已返还次数\">\n"
//                    + "            <value>2</value>\n"
//                    + "        </column>\n"
//                    + "        <column name=\"本次返还次数\">\n"
//                    + "            <value/>\n"
//                    + "        </column>\n"
//                    + "        <column name=\"是否存在未返厂物资\">\n"
//                    + "            <value/>\n"
//                    + "        </column>\n"
//                    + "        <column name=\"返还关联表单\">\n"
//                    + "            <value/>\n"
//                    + "        </column>\n"
//                    + "        <column name=\"状态_抓取存在未返厂物资数据\">\n"
//                    + "            <value>1</value>\n"
//                    + "        </column>\n"
//                    + "        <column name=\"单据编号1\">\n"
//                    + "            <value/>\n"
//                    + "        </column>\n"
//                    + "    </values>\n"
//                    + "</formExport>\n"
//                    + "";
//
//            ServiceResponse t = fs.launchFormCollaboration(token.getId(), "002218", "o_r_01", "测试", xml, new Long[]{}, "1", null);
//
//            logger.info("result:" + t.getResult());
//
//            logger.info("result:" + result);
        } catch (Exception ex) {
            ex.printStackTrace();
            logger.error(ex);
        }
        return result;
    }
}
